/**
 * Class for the SubChair
 * Author: My Hoang
 * TCSS360
 */

package superConference;

import java.util.ArrayList;
import java.util.List;


/**
 * The class for the SubChair extends AbstractUser
 * 
 * @author MyHoang
 *
 */
public class SubProgramChair extends AbstractUser
{
	protected ArrayList<Paper> my_papers;
	
	/**
	 * Constructor for the SubChair
	 * @param userID ID of the SubChair
	 * @param email Email of the SubChair
	 * @param name Name of the Subchair
	 */
	SubProgramChair(int userID, String email, String name) 
	{
		super(userID, email, name);
		setPapers(new ArrayList<Paper>());
	}
	
	/**
	 * Method to grab the paper from the library using paperID
	 * @param paperID
	 */
	public Paper getPaper(int paperID)
	{
		Paper returnPaper = null;
		for(Paper paper : my_papers)
		{
			if(paper.getId() == paperID)
			{
				returnPaper =  paper;
			}
		}
		return returnPaper;
			
	}
	
	/**
	 * getPaper method
	 * @return Arraylist of paper.
	 */
	public ArrayList<Paper> getPaper()
	{
		return my_papers;
	}
	
	/**
	 * Add paper to the list.
	 * @param thePaper
	 */
	public void addPaper(Paper thePaper)
	{
		my_papers.add(thePaper);
		thePaper.assignTo(this.getEmail());
	}
	
	/**
	 * Set the list of paper to the subchair.
	 * @param thePapers
	 */
	public void setPapers(ArrayList<Paper> thePapers)
	{
		my_papers = thePapers;
	}
	/**
	 * Class to Assign paper for reviewer to be review.
	 * @param theReviewer The Reviewer assign to the paper
	 * @param userID The Reviewer ID
	 * @param the_paper 
	 * @return the Reviewer with the paper assign to.
	 */
	public void assignReviewer(UserManager manager, int userID, Paper the_paper)
	{
		manager.getReviewerByID(userID).addPaper(the_paper);
	}
	
	
	/**
	 * Class to recommend paper to the ProgramChair
	 * @param rec Boolean if the Subchair is recommend the paper or not.
	 * @param theAuthors List of authors
	 * @param theID The paper ID
	 * @return The recommend status of the found paper.
	 */

	@SuppressWarnings("unused")
	private boolean setRecommendation(boolean rec, List <Author> theAuthors, int theID)
	{
		boolean found = false;
		for(Author a : theAuthors)
		{
			for(Paper p : a.getListOfPaper())
			{
				if(p.getId() == theID)
				{
					p.rec(rec);
					found = true;					
				}
			}
		}
		return found;
	}
	
	/**
	 * Create a List of paper String.	 
	 * @param the_list
	 * @return the List paper.
	 */
	public String paperList(List<Author> the_list)
	{
		StringBuilder sb = new StringBuilder();
		for(Author a : the_list)
		{
			for(Paper p: a.getListOfPaper())
			{
				sb.append(p.toString() + "\n");
			}
		}
		if(sb.length() == 0)
		{
			sb.append("No papers");
		}
		return sb.toString();
	}
	
	/**
	 * The list of reviewers String
	 * @param theReviewer
	 * @return the list of Reviewer.
	 */
	public String theReviewer(List<Reviewer> theReviewer)
	{
		StringBuilder sb = new StringBuilder();
		for(Reviewer r : theReviewer)
		{
			sb.append("ReviewerID : ");
			sb.append(r.getUserID());
			sb.append("\tName : ");
			sb.append(r.getName() + "\n");
			
			for(Review p : r.getReviews())
			{
				sb.append("Paper ID: ");
				sb.append(p.getID());
				sb.append("\t");
				sb.append(p.toString());
				sb.append("\n");
			}
		}
		return sb.toString();
	}

}
